package com.jqr.activity.fragmentmanagerdemo.fragments;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.jqr.activity.fragmentmanagerdemo.MainActivity;
import com.jqr.activity.fragmentmanagerdemo.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link IndexFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class IndexFragment extends Fragment {

    private  IFragmentCallback callback;

    private View root;

    public void setCallback(IFragmentCallback callback) {
        this.callback = callback;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle=getArguments();
        if(bundle!=null){
            String str= bundle.getString("message");
            Log.d("TAG",str);
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        if(root==null){
           root= inflater.inflate(R.layout.fragment_index, container, false);
        }

        Button btnSendMsgToActivity=root.findViewById(R.id.btnSendMsgToActivity);


        btnSendMsgToActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.sendMsgToActivity("send_msg_to_activity");
            }
        });


        return  root;
    }
}